<template>
	<div class="form">
	姓名:<input type="text" v-model="name"/><br/>
	年龄:<input type="number" v-model="age"><br/>
	性别: &nbsp;男:<input type="radio" value="男" v-model="sex"/>
		 &nbsp;女:<input type="radio" value="女" v-model="sex"/> <br/>
	<button @click="submit()">提交</button>
	</div>
</template>

<script>
	export default{
		name:"Make",
		props:["stu1"],
		data:function(){
			return{
				name:this.stu1==null?"":this.stu1.name,
				age:this.stu1==null?"":this.stu1.age,
				sex:this.stu1==null?"":this.stu1.sex,
				generateId:(function *generateId(){
							let id=2;
							while(true){
								yield id++;
							}
						})()
			}
		},
		methods:{
		getId(){
			return this.generateId.next().value
		},
		submit() {
			if(this.stu1==null){
				let id= this.getId();
				let obj = {
					id,
					name:this.name,
					age:this.age,
					sex:this.sex
				}
				this.$emit("transobj",obj);
				
			}else{
				this.stu1.name=this.name;
				this.stu1.age=this.age;
				this.stu1.sex=this.sex;
				this.$emit("update")
				
				
			}
			this.name="";
			this.age="";
			this.sex="";
			}
		
		}
		}

</script>

<style>
</style>